package com.spa.interfaces.massagist;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.StpUtil;
import com.spa.application.dto.login.LoginDTO;
import com.spa.application.query.member.LoginQuery;
import com.spa.application.query.member.SmsQuery;
import com.spa.application.service.massagist.MassagistLoginApplicationService;
import com.spa.infrastructure.common.ResponseMessage;
import com.spa.infrastructure.enums.dict.base.RequestSourceEnum;
import com.spa.infrastructure.service.sms.GenerateSmsCodeKey;
import com.spa.infrastructure.service.sms.SmsProvider;
import com.spa.infrastructure.util.SessionUtil;
import com.spa.interfaces.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/massagist")
@Slf4j
public class MassagistLoginController extends BaseController {

    @Resource
    private MassagistLoginApplicationService loginService;

    @Resource
    private SmsProvider smsProvider;

    @Resource
    private GenerateSmsCodeKey smsCodeKey;

    @PostMapping("/login")
    @SaIgnore
    public ResponseMessage<LoginDTO> massagistLogin(@Validated @RequestBody LoginQuery query) {
        return responseHelper.success(loginService.smsLogin(query));
    }

    @PostMapping("/outLogin")
    public ResponseMessage outLogin() {
        StpUtil.logout();
        return responseHelper.success();
    }

    @PostMapping("/wxConcerned")
    public ResponseMessage wxopen() {
        return responseHelper.success(loginService.getWxConcerned(SessionUtil.getUser().getUserId(), RequestSourceEnum.Massagist));
    }

    @PostMapping("/sendSms")
    @SaIgnore
    public ResponseMessage sendSms(@Validated @RequestBody SmsQuery query) {
        loginService.sendSms(query.getPhone());
        return responseHelper.success();
    }

}
